//
//  HRBannerCell.m
//  Hear
//
//  Created by mac on 2017/12/28.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRBannerCell.h"
@interface HRBannerCell ()
@property (nonatomic, strong)UIView *contView;
@property (nonatomic, strong)UIImageView *iconImageView;
@property (nonatomic, strong)UILabel *nickNameLabel;
@property(nonatomic, strong)UIImageView *showImagView;
@property(nonatomic, strong)UILabel *contentLabel;
@property(nonatomic, strong)UILabel *moneyLabel;

@end
@implementation HRBannerCell

-(void)setLayout:(HRFollowDynamicLayout *)layout{
    HRDynamicModel *dynamicModel = layout.dynamicModel;
    
    self.nickNameLabel.text = dynamicModel.NickName;
    [self.iconImageView setImageURL:[NSURL URLWithString:dynamicModel.UserPictureName]];
    [self.showImagView setImageURL:[NSURL URLWithString:dynamicModel.MomentDetaiModel.ListMediaUrl]];
    self.contentLabel.text = dynamicModel.MomentNotes;
    
    self.moneyLabel.text = [NSString stringWithFormat:@"-读广告赢现金（%@元）-",dynamicModel.MomentDetaiModel.Commission];
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRBannerCell";
    
    HRBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRBannerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat leftPading = 15;

        
        self.backgroundColor = CustomColor(240, 240, 240, 1);
        self.contView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 405)];
        self.contView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.contView];
        
        UIImageView *iconImageView = [UIImageView new];
        iconImageView.frame = CGRectMake(leftPading, leftPading, 50, 50);
        iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        iconImageView.clipsToBounds = YES;
        iconImageView.layer.cornerRadius = 25;
        [self.contView addSubview:(self.iconImageView = iconImageView)];
        iconImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
//            if (weakSelf.clickIconBlock){
//                weakSelf.clickIconBlock();
//            }
        }];
        [iconImageView addGestureRecognizer:iconTap];
        
        
        self.nickNameLabel = [UILabel new];
        self.nickNameLabel.frame = CGRectMake(iconImageView.right+leftPading, iconImageView.centerY-12, kFullWidth-leftPading*3-iconImageView.width, 25);
        self.nickNameLabel.textColor = FirstTextColor;
        self.nickNameLabel.font = CustomUIFont(16);
        [self.contView addSubview:self.nickNameLabel];
        
        
        UILabel *typeLabel = [UILabel new];
        typeLabel.frame = CGRectMake(self.contView.width-60, self.nickNameLabel.top, 40, 25);
        typeLabel.textColor = FirstTextColor;
        typeLabel.font = CustomUIFont(16);
        [self.contView addSubview:typeLabel];
        typeLabel.text = @"广告";
        
        self.contentLabel = [UILabel new];
        self.contentLabel.frame = CGRectMake(iconImageView.left, iconImageView.bottom+leftPading, kFullWidth-leftPading*2, 40);
        self.contentLabel.textColor = FirstTextColor;
        self.contentLabel.font = CustomUIFont(16);
        [self.contView addSubview:self.contentLabel];
        
        UIImageView *showImagView = [UIImageView new];
        showImagView.backgroundColor = CustomColor(240, 240, 240, 1);
        [_contView addSubview:(self.showImagView=showImagView)];
        showImagView.frame = CGRectMake(iconImageView.left, self.contentLabel.bottom+leftPading, kScreenWidth/3*2+30, 200);
        
        self.moneyLabel = [UILabel new];
        self.moneyLabel.frame = CGRectMake(iconImageView.left, showImagView.bottom+leftPading, showImagView.width/2+20, 30);
        self.moneyLabel.textColor = FirstTextColor;
        self.moneyLabel.font = CustomUIFont(13);
        [self.contView addSubview:self.moneyLabel];
//        self.moneyLabel.text = @"-读广告赢现金（2元）-";
        
        UIButton *answerButton = [UIButton buttonWithType:0];
        [answerButton setTitle:@"・ 我来读 ・" forState:0];
        [answerButton setTitleColor:BlueColor forState:0];
        answerButton.titleLabel.font = CustomUIFont(16);
        [answerButton addTarget:self action:@selector(answerButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [_contView addSubview:answerButton];
        answerButton.frame = CGRectMake(showImagView.right-100, _moneyLabel.top, 100, 30);
        answerButton.layer.cornerRadius = 8;
        answerButton.clipsToBounds = YES;
        answerButton.layer.borderColor = BlueColor.CGColor;
        answerButton.layer.borderWidth = 1;
        
        
        DDLog(@"%f",answerButton.bottom);
    }
    return self;
}

- (void)answerButtonClick{
    if (self.answerButtonBlock){
        self.answerButtonBlock();
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
